package com.share.two.f_mysql_jdbc.c_c3p0;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Service;

import com.share.two.f_mysql_jdbc.entity.User;


@Service
public class UserDao {

	@Autowired
	JdbcTemplate jdbcTemplate;

	public void update(User user) {
		String sql = "update t_user set username=?,password=? where id =?";
		Object[] args = {user.getUsername(), user.getPassword(), user.getId()};
		jdbcTemplate.update(sql, args);
	}

	public List<User> selectAll() {
		return jdbcTemplate.query("select * from t_user", 
				ParameterizedBeanPropertyRowMapper.newInstance(User.class));
	}

}
